<html>
<head><meta charset="utf-8"><title>rustfix for `try!` to `?` · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html">rustfix for `try!` to `?`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178031362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178031362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178031362">(Oct 13 2019 at 10:02)</a>:</h4>
<p>How hard would it be to make the current deprecation warning for <code>try!</code> rustfixable?</p>



<a name="178031553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178031553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178031553">(Oct 13 2019 at 10:06)</a>:</h4>
<p>It looks like the current warning comes purely from the use of <code>rustc_deprecated</code>. Could the compiler build in support for that deprecation itself, and then offer a rustfix?</p>



<a name="178031579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178031579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178031579">(Oct 13 2019 at 10:07)</a>:</h4>
<p>(I can imagine adding support for rustfix suggestions to deprecation attributes, but that would require a more general "replace this with that" syntax in the attribute, and I don't mind special-casing this for simplicity.)</p>



<a name="178031865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178031865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178031865">(Oct 13 2019 at 10:13)</a>:</h4>
<p>I'm trying to figure out where the <code>suggestion</code> in <code>RustcDeprecation</code> gets used.</p>



<a name="178032022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032022">(Oct 13 2019 at 10:17)</a>:</h4>
<p>AFAIK just replacing one with the other will not always type-solve, anymore.</p>



<a name="178032030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032030">(Oct 13 2019 at 10:17)</a>:</h4>
<p>This might or might not be the case why we do not do it already.</p>



<a name="178032106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032106">(Oct 13 2019 at 10:19)</a>:</h4>
<p>Under what circumstances would it not?</p>



<a name="178032156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032156">(Oct 13 2019 at 10:20)</a>:</h4>
<p>/me would like to get rustfix to help converting 400+ uses of <code>try!</code> in a project.</p>



<a name="178032178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032178">(Oct 13 2019 at 10:21)</a>:</h4>
<p>(Also, I found <code>late_report_deprecation</code> where the suggestion gets used.)</p>



<a name="178032389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032389">(Oct 13 2019 at 10:26)</a>:</h4>
<p>if it's just to actually translate them, use rustfmt</p>



<a name="178032411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032411">(Oct 13 2019 at 10:27)</a>:</h4>
<p>with <code>use_try_shorthand = true</code> specifically</p>



<a name="178032473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032473">(Oct 13 2019 at 10:28)</a>:</h4>
<p>should be easier than to teach how to do it to the compiler :)</p>



<a name="178032480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032480">(Oct 13 2019 at 10:28)</a>:</h4>
<p>Oh, handy; I didn't know <code>rustfmt</code> could do that.</p>



<a name="178032490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032490">(Oct 13 2019 at 10:28)</a>:</h4>
<p>I'll have to figure out how to disable the <em>rest</em> of <code>rustfmt</code> so I don't get a pile of things mixed into one commit, but that should still be easier. :)</p>



<a name="178032585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032585">(Oct 13 2019 at 10:30)</a>:</h4>
<p><span class="user-mention" data-user-id="116113">@lqd</span> Thanks!</p>



<a name="178032817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032817">(Oct 13 2019 at 10:37)</a>:</h4>
<p>you're welcome</p>



<a name="178032818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032818">(Oct 13 2019 at 10:37)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span>  Ah, I see; across the whole project, I did indeed have <em>one</em> case where switching from <code>try!</code> to <code>?</code> resulted in insufficient information for type inference.</p>



<a name="178032897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032897">(Oct 13 2019 at 10:39)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> aww and here I just crafted a convulted example: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=cdaaa9ad06842745213d63a786c391c8" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=cdaaa9ad06842745213d63a786c391c8">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=cdaaa9ad06842745213d63a786c391c8</a></p>



<a name="178032946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032946">(Oct 13 2019 at 10:40)</a>:</h4>
<p>I believe this is mostly because <code>?</code> is able to work with <code>Option</code>s and other <code>Try</code> implementing types and <code>r#try</code> is just for <code>Result</code>.</p>



<a name="178032947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032947">(Oct 13 2019 at 10:40)</a>:</h4>
<p>Right, that's the case I ran into as well.</p>



<a name="178032955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178032955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178032955">(Oct 13 2019 at 10:41)</a>:</h4>
<div class="codehilite"><pre><span></span>error[E0282]: type annotations needed for `&amp;(_, _)`
</pre></div>



<a name="178033139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178033139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178033139">(Oct 13 2019 at 10:47)</a>:</h4>
<p>I'm having a lot of trouble getting rustfmt to <em>not</em> do things. <code>disable_all_formatting</code> also disables <code>use_try_shorthand</code>...</p>



<a name="178033239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178033239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178033239">(Oct 13 2019 at 10:50)</a>:</h4>
<p>I can avoid a <em>lot</em> of it with <code>max_width=400</code>, but I still have a lot of cases like this to sort through:</p>
<div class="codehilite"><pre><span></span>-        _ =&gt; {
-            return Err(format!(&quot;Remote does not have either a tag or branch named {}&quot;, tag).into())
-        }
+        _ =&gt; return Err(format!(&quot;Remote does not have either a tag or branch named {}&quot;, tag).into()),
</pre></div>



<a name="178033414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178033414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178033414">(Oct 13 2019 at 10:57)</a>:</h4>
<p>/me shrugs; still less trouble to sort through than doing it by hand.</p>



<a name="178033415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/rustfix%20for%20%60try%21%60%20to%20%60%3F%60/near/178033415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/rustfix.20for.20.60try!.60.20to.20.60.3F.60.html#178033415">(Oct 13 2019 at 10:57)</a>:</h4>
<p>Thanks again.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>